package com.example.demo01.controllter;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author admin
 * @Description 测试是否启动
 * @date 2020-07-04 17:33:00
 */
@Slf4j
@RequestMapping(value = "/api01")
@RestController
public class Test {

    @GetMapping(value = "/test")
    public void test() {
        log.info("################### test01 is ok #################");
    }

    public static void main(String[] args) {
        System.out.println("###################### list.for #######################");
        List<String> list = new ArrayList<>(16);
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        // 遍历List
        for (String s : list) {
            // 1 2 3 4 5 6
            System.out.print(s + "\t");
        }
        System.out.println();
        System.out.println("###################### map in list  #######################");
        Map<List<String>, String> map = new HashMap<>(16);
        map.put(list, "1");
        // {[1,2,3,4,5,6] = 1}
        System.out.println("map = " + map);
        // list in map
        List<Map<String, String>> objects = Lists.newArrayList();
        Map<String, String> stringMap = Maps.newHashMap();
        stringMap.put("1", "1");
        stringMap.put("2", "2");
        stringMap.put("3", "3");
        stringMap.put("4", "4");
        stringMap.put("5", "5");
        objects.add(stringMap);
        for (Map<String, String> object : objects) {
            System.out.println("object.get(\"1\") = " + object.get("1"));
            System.out.println("object.get(\"2\") = " + object.get("2"));
            System.out.println("object.get(\"3\") = " + object.get("3"));
            System.out.println("object.get(\"4\") = " + object.get("4"));
            System.out.println("object.get(\"5\") = " + object.get("5"));
        }
        System.out.println("###################### map.for  #######################");
        Set<Map.Entry<List<String>, String>> entries = map.entrySet();
        // 遍历Map
        for (Map.Entry<List<String>, String> entry : entries) {
            System.out.println("entry.getKey() = " + entry.getKey());
            System.out.println("entry.getValue() = " + entry.getValue());
        }

    }

}
